package com.wm.calendar;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

public class CalendarTest {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        Scanner in = new Scanner(System.in);
        System.out.println("请输入年份:");
        int year = in.nextInt();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, 4);
        int maxDate = c.getActualMaximum(Calendar.DATE);
        int sundays = 0;
        for(int i = 1; i <= maxDate; i ++) {
            c.set(Calendar.DATE, i);
            //判断是周日
            if(c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                sundays ++;
                //第二个周日，返回
                if(sundays == 2) {
                    break;
                }
            }
        }
        String date = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
        System.out.printf("%s年的母亲节是：%s",year,date);
    }
}
